package pub

import (
	"context"
	"fmt"
	"github.com/apache/rocketmq-client-go/v2"
	"github.com/apache/rocketmq-client-go/v2/primitive"
	"github.com/pkg/errors"
)

func SendOrderlyMessage(p rocketmq.Producer, topic, message ,key string) error {
	msg := primitive.NewMessage(topic, []byte(message))
	msg.WithShardingKey(key)
	res, err := p.SendSync(context.Background(), msg)

	if err != nil {
		return errors.Wrap(err, "ERR: fail to send message")
	}

	fmt.Printf("send message success: result=%s\n", res.String())
	return nil
}